<?php defined('SYSPATH') or die('No direct script access.');

class Model_Services_Finalsegment extends Model{
	
	public $final_segment = NULL;
		
	public function __construct($final_segment_id=false){
		if ($final_segment_id) $this->final_segment = $this->get($final_segment_id);
	}
	
	public function get($id){
		return ORM::factory("dao_finalsegments")->find($id);
	}
	
	public function getFinalSegment(){
		return Model_Segment::create($this->final_segment->final_segment);
	}
	
	public function getFirstDerivative(){
		return Model_Segment::create($this->final_segment->first_derivative);
	}
	
	public function getSecondDerivative(){
		return Model_Segment::create($this->final_segment->second_derivative);
	}
	
	public function getThirdDerivative(){
		return Model_Segment::create($this->final_segment->third_derivative);
	}
	
	public function getFourthDerivative(){
		return Model_Segment::create($this->final_segment->fourth_derivative);
	}	
	
		
	public function save($id, array $data){
		$this->final_segment = ($id > 0) ? ORM::factory("dao_finalsegments",$id) : ORM::factory("dao_finalsegments");
		
		$this->final_segment->final_segment = $data["final_segment"];
		$this->final_segment->first_derivative = $data["first_derivative"];
		$this->final_segment->second_derivative = $data["second_derivative"];
		$this->final_segment->third_derivative = $data["third_derivative"];
		$this->final_segment->fourth_derivative = $data["fourth_derivative"];
		
		$this->final_segment->save();
						
		return $this->final_segment->id;
	}
	
	public function delete($id){
		/*$this->rawsignal = ORM::factory("dao_rawsignal",$id);
		$this->rawsignal->delete();
		return "Registro: ".$this->rawsignal->id." eliminado con exito";*/
	}
	
	
}
?>